package net.zjitc.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Administrator on 2017/9/25.
 */
@WebServlet(name = "HttpServletOne",urlPatterns = "/hServlet")//有这个urlPatterns = "hServlet"就不用在web.xml里面配置了
public class HttpServletOne extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*//设置响应 的编码方式
        response.setCharacterEncoding("utf-8");
        //设置响应头，给浏览器用（设置浏览器的编码方式）
        response.setHeader("Content-Type","text/html;charset=utf-8");*/
        response.setContentType("text/html;charset=utf-8");


        //设置三秒后自动跳转至指定网页
        //response.setHeader("refresh","3;http://www.zjitc.net");
        //刷新当前页面
        //response.setHeader("refresh","3");
        //跳转到gServlet
        //response.sendRedirect("/snc/gServlet");
        response.sendRedirect("/snc/login/login.jsp");
        PrintWriter out = response.getWriter();
        out.write("http  get ...  ");
        out.write("测试http");
    }
}
